package org.ecshop.controllers;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.ecshop.models.OrderGoods;
import org.ecshop.models.OrderInfo;

import will.icecoffe.core.DataAccessException;
import will.icecoffe.core.SimpleDataAccessService;

import com.opensymphony.xwork2.ModelDriven;



public class OrderInfoController implements ModelDriven<Object> {

	private List<OrderInfo> list = new ArrayList<OrderInfo>();
	
	private int key;
	
	public int getKey() {
		return key;
	}

	public void setKey(int key) {
		this.key = key;
	}

	
	@Resource(name="DAS")
	private SimpleDataAccessService<OrderInfo> das;
	@Resource(name="DAS")
	private SimpleDataAccessService<OrderGoods> gdas;

	
	public String index() throws DataAccessException {
		list = das.find("hql", "findOderInfoByUserId", key);
		for(OrderInfo oi : list) {
			
			switch(Integer.valueOf(oi.getOrderStatus())) {
				case 0: oi.setOrderStatus("未确认"); break;
				case 1: oi.setOrderStatus("确认"); break;
				case 2: oi.setOrderStatus("已取消"); break;
				case 3: oi.setOrderStatus("无效"); break;
				case 4: oi.setOrderStatus("退货"); break;
			}
			
			switch(Integer.valueOf(oi.getShippingStatus())) {
				case 0: oi.setShippingStatus("未发货"); break;
				case 1: oi.setShippingStatus("已发货"); break;
				case 2: oi.setShippingStatus("已收货"); break;
				//case 3: oi.setShippingStatus("未确认"); break;
				case 4: oi.setShippingStatus("退货"); break;
			}
			
			switch(Integer.valueOf(oi.getPayStatus())) {
				case 0: oi.setPayStatus("未付款"); break;
				case 1: oi.setPayStatus("付款中"); break;
				case 2: oi.setPayStatus("已付款"); break;
			}
			
			List<OrderGoods> oglist = gdas.find("hql", "findOrderGoodsByOrderId", oi.getOrderId());
			oi.setGoods(oglist);
		}
		return null;
	}
	
	@Override
	public Object getModel() {
		return list;
	}

}
